<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/10
 * Time: 21:59
 */

namespace app\lnadmin\model\admin;

use dateset\Dateset;
use app\lnadmin\model\core\InitModel;


/**
 * 点赞记录
 * Class ViewLog
 * @package app\model\admin
 */
class UserLog extends InitModel
{
    // 定义表
    protected $name = 'user_log';

    // 第一自动写入时间字段
    protected $createTime = 'create_time';

    // 删除
    public static function del($id)
    {
        $data = self::whereIn('id', $id)->find();
        if (!$data) return false;
        self::destroy($id);
        return true;
    }
    // 新增
    public static function add($post)
    {
        $model = new self();
        return $model->save($post);
     } 

public function get_log_list($param = [])
    {
        $rows = empty($param['limit']) ? get_config('app.pages') : $param['limit'];
        $content = \think\facade\Db::name('UserLog')
             ->field('id,username,ip,content,param,create_time')
            ->order('create_time desc')
            ->paginate($rows, false, ['query' => $param]);
        
        $content->toArray();
        $date_set = new Dateset();
        foreach ($content as $k => $v) {
            $data = $v;
            $param_array = json_decode($v['param'], true);
            $name = '';
            if (!empty($param_array['name'])) {
                $name = '：' . $param_array['name'];
            }
            if (!empty($param_array['title'])) {
                $name = '：' . $param_array['title'];
            }
            $data['content'] = $v['content'] . $name;
            $data['times'] = $date_set->time_trans($v['create_time']);
            $data['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
            $content->offsetSet($k, $data);
        }
        return $content;
    }

    }